import {
  sceneListAPI,
  sceneDeleteAPI,
  sceneGetAPI,
  sceneUpdateAPI,
  itemListAPI,
  itemGetAPI,
  itemDeleteAPI,
  itemUpdateAPI,
  itemFetchallSimplyAPI,
  sceneOptionListAPI,
  sceneOptionGetAPI,
  sceneOptionDeleteAPI,
  sceneOptionUpdateAPI,
} from "@/api/configApi";
const state = {
  sceneList: [], //列表数据
};

const mutations = {
  SET_LISTDATA: (state, data) => {
    state.sceneList = data;
  },
};

const actions = {
  //场景配置
  sceneList({ commit }, params) {
    return new Promise((resolve, reject) => {
      sceneListAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  //场景类型下拉框数据
  sceneTypeOption({ commit }, params) {
    return new Promise((resolve, reject) => {
      sceneListAPI(params)
        .then((res) => {
          console.log(res);
          let arr = [];
          res.data.forEach((item) => {
            let obj = { value: item.id, label: item.question };
            arr.push(obj);
          });
          resolve(arr);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 保存
  sceneSave({ commit }, params) {
    return new Promise((resolve, reject) => {
      sceneUpdateAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 查询
  sceneDetail({ commit }, params) {
    return new Promise((resolve, reject) => {
      sceneGetAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  sceneDelete({ commit }, params) {
    return new Promise((resolve, reject) => {
      sceneDeleteAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  //指标管理
  itemList({ commit }, params) {
    return new Promise((resolve, reject) => {
      itemListAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 保存
  itemUpdate({ commit }, params) {
    return new Promise((resolve, reject) => {
      itemUpdateAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 查询
  itemGet({ commit }, params) {
    return new Promise((resolve, reject) => {
      itemGetAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  itemDelete({ commit }, params) {
    return new Promise((resolve, reject) => {
      itemDeleteAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  //指标下拉框
  itemFetchallSimply({ commit }, params) {
    return new Promise((resolve, reject) => {
      itemFetchallSimplyAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  //场景管理
  sceneOptionList({ commit }, params) {
    return new Promise((resolve, reject) => {
      sceneOptionListAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 保存
  sceneOptionUpdate({ commit }, params) {
    return new Promise((resolve, reject) => {
      sceneOptionUpdateAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  // 查询
  sceneOptionGet({ commit }, params) {
    return new Promise((resolve, reject) => {
      sceneOptionGetAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },

  sceneOptionDelete({ commit }, params) {
    return new Promise((resolve, reject) => {
      sceneOptionDeleteAPI(params)
        .then((res) => {
          resolve(res);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
